﻿using System;
using System.Collections.Generic;
using System.Text;
using Dune.Common.Services;
using NHibernate;

namespace Dune.DAL.Common.SessionManagment
{
    public class OneSessionProvider : ISessionProvider
    {
        ISession session;

        public ISession GetSession()
        {
            if (session == null)
            {
                IInterceptorProvider interceptorProvider = Locator.GetService<IInterceptorProvider>();

                IInterceptor interceptor =
                     interceptorProvider != null ? interceptorProvider.GetInterceptor(Locator.GetService<ISessionFactory>()) : null;

                session = interceptor != null ?
                     Locator.GetService<ISessionFactory>().OpenSession(interceptor) : Locator.GetService<ISessionFactory>().OpenSession();

            }
            return session;
        }
    }
}
